<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <p>温馨提示：该cookie 10s后过期</p>
  <button class="login">登录</button>
  <button class="user">访问user</button>
  <script src="https://unpkg.com/axios/dist/axios.min.js"></script>
  <script>

    const service = axios.create({
      withCredentials: true // 允许携带cookie
    })
    var loginBtn = document.querySelector('.login')
    loginBtn.addEventListener('click', function () {
      service.post('http://localhost:3000/login')
        .then(res => {
          console.log(res);
        })
        .catch(err => {
          console.log(err);
        })
    })


    var userBtn = document.querySelector('.user')
    userBtn.addEventListener('click', function () {
      service.get('http://localhost:3000/user')
        .then(res => {
          console.log(res)
        })
        .catch(err => {
          console.error(err);
        })
    })
  </script>
</body>

</html>